home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / dev / src / MiniStat.lha / MiniStat / MiniStat027.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-29  |  3.7 KB  |  148 lines

  1. /*Very simple statistical program by Angelo Theodorou ©2000*/
  2.  
  3. #define CLEAR 12              /*0x12 cleans the screen on many terminals*/
  4. #include <stdio.h>
  5. #include <math.h>             /*Included for the sqrt() function*/
  6.  
  7. /*I is the counter for the FOR cycle*/
  8.  
  9. /*Q is the number of the value inserted by the user*/
  10.  
  11. /*A represent always an adding, so A is the basic adding of the values, */
  12. /*AR is the adding of the rejectings, ARM is the adding between the values of global mean minus the rejectings, */
  13. /*while ASQRM is the adding between the squared rejectings*/
  14.  
  15. /*M represent always a mean, so M is the mean between the values, */
  16. /*MR is the mean between the rejectings, MRM is the mean between the values of global mean minus the rejectings, */
  17. /*while MSQRM is the mean between the squared rejectings*/
  18.  
  19. /*V represent always an array of Max 100 values, so V[100] are the values inserted by the user, */
  20. /*VR[100] contains the rejectings, VRM[100] contains the values of global mean minus the rejectings, */
  21. /*while VSQRM[100] are the squared rejectings*/
  22.  
  23. /*MAX and MIN are the maximum and minimum value inserted*/
  24.  
  25.    int i,q,a,ar,arm,asqrm,max,min,v[100],vr[99];
  26.    float m,mr,mrm,msqrm,vrm[100],vsqrm[100];
  27.  
  28. void ReadData();
  29. void    Mean();
  30. void    MaxMin();
  31. void    RejMean();
  32. void    SimMedRej();
  33. void    Deviation();
  34.  
  35.  
  36. main(){
  37.  
  38.     printf("\t®MiniStat v 0.2.7 ©2000 by Encelo\n");
  39.  
  40.      ReadData();
  41.     Mean();
  42.     MaxMin();
  43.     RejMean();
  44.     SimMedRej();
  45.     Deviation();
  46. }
  47.  
  48. void ReadData(){        /*Reads the values to compute on*/
  49.     printf("\nHow many decimal values do you want to insert?(Max 100, 0 to quit): ");
  50.     scanf("%d",&q);
  51.     if (q==0) {
  52.              printf("Quitting...\n"); /*If you insert 0 the program quits*/
  53.              exit(21);
  54.              };
  55.     for (i=1;i<=q;i++)
  56.         {
  57.         printf("Value No.%d:",i);
  58.         scanf("%d",&v[i]);
  59.         }
  60.  
  61.     printf("\nOk, you have inserted all the %d values, now I'm calculating...\n\n",q);
  62. }
  63.  
  64. void Mean(){            /*Calculates the mean between the values*/
  65.     for (i=1;i<=q;i++)
  66.         {
  67.         a+=v[i];
  68.         }
  69.     m=(float)a/q;
  70.     printf("The mean between the %d values is: %f\n",q,m);
  71. }
  72.  
  73. void MaxMin(){         /*Determines the Max and Min value*/
  74.     max=0;
  75.     for (i=1;i<=q;i++)
  76.         {
  77.         if (v[i]>max)
  78.             {
  79.                 max=v[i];
  80.             }
  81.         }
  82.     min=max;
  83.     for (i=1;i<=q;i++)
  84.         {
  85.         if (v[i]<min)
  86.             {
  87.                 min=v[i];
  88.             }
  89.         }
  90.     printf("Maximum value: %d\n",max);
  91.     printf("Minimum value: %d\n",min);
  92.     printf("The values dispersion is: %d\n",max-min);
  93. }
  94.  
  95. void RejMean(){        /*The mean between the rejectings*/
  96.     for (i=1;i<=q-1;i++)
  97.         {
  98.         if (v[i]-v[i+1]>0)         /*This*/
  99.             {                     /*is*/
  100.             vr[i]=v[i]-v[i+1];    /*done*/
  101.             }                     /*to*/
  102.         else                       /*calculate*/
  103.             {                     /*the*/
  104.             vr[i]=v[i+1]-v[i];    /*absolute*/
  105.             }                     /*value*/
  106.         }
  107.     for (i=1;i<=q-1;i++)
  108.         {
  109.         ar+=vr[i];
  110.         }
  111.     mr=(float)ar/(q-1);
  112.     printf("The mean between the %d rejectings among the values is: %f\n",q-1,mr);
  113. }
  114.  
  115. void SimMedRej(){   /*The mean among the values of global mean minus the rejectings*/
  116.     for (i=1;i<=q;i++)
  117.         {
  118.         if (v[i]-m>0)              /*This*/
  119.             {                     /*is*/
  120.             vrm[i]=(float)v[i]-m; /*done*/
  121.             }                     /*to*/
  122.         else                       /*calculate*/
  123.             {                     /*the*/
  124.             vrm[i]=(float)m-v[i]; /*absolute*/
  125.             }                     /*value*/
  126.         }
  127.     for (i=1;i<=q;i++)
  128.         {
  129.         arm+=vrm[i];
  130.         }
  131.     mrm=(float)arm/q;
  132.     printf("The simple medium rejecting is: %f\n",mrm);
  133. }
  134.  
  135. void Deviation(){      /*It's like the SimMedRej, but it operates on the squared values*/
  136.     for (i=1;i<=q;i++)
  137.         {
  138.         vsqrm[i]=vrm[i]*vrm[i];
  139.         }
  140.     for (i=1;i<=q;i++)
  141.         {
  142.         asqrm+=vsqrm[i];
  143.         }
  144.     msqrm=(float)asqrm/q;
  145.     printf("The variant is: %f\n",msqrm);
  146.     printf("The standard deviation is: %f\n",sqrt(msqrm));
  147. }
  148.